package com.xyf.sys.util;

import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

/**
 * @Author R-H
 * @Date 2024/3/71904
 * @Description
 */
@Slf4j
public class EMSUtils {

    private static final String EMS_BASE_URL = "https://api.ems.com.cn/amp-prod-api/f/amp/api/open";

    public static String doPost(String apiCode, String senderNo, String authorization, String logitcsInterface, String key) {
        log.info("logitcsInterface {}  , apiCode{}, senderNo {} authorization {}, key {} ", logitcsInterface, apiCode, senderNo, authorization, key);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("apiCode", apiCode);
        jsonObject.put("senderNo", senderNo);
        jsonObject.put("authorization", authorization);
        jsonObject.put("msgType", "0");//0-json 1-xml 默认为json
        jsonObject.put("timeStamp", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        jsonObject.put("version", "V1.0.0");
        String content = logitcsInterface + key;
        jsonObject.put("logitcsInterface", CryptoThirdSM4Tools.sm4Encrypt(content, key));
        log.info("ems body {}", jsonObject.toJSONString());
        String post = HttpUtil.post(EMS_BASE_URL, jsonObject);
        log.info(" post data {}", post);
        return post;
    }
}
